﻿--#include "data\functions\Fuben\SpaceTrial.lua" once   --血域试炼

local npcId = 149
NpcDialog[npcId] = {}
local t = NpcDialog[npcId]

t.main = function(sysarg)
	local strCond = ""
	local circleLimit= SpaceTrialCfg.enterLevelLimit[1]
	local levelLimit = SpaceTrialCfg.enterLevelLimit[2]

	local strColor1 = Lang.ScriptTips.Color_Greed
	if not Actor.checkActorLevel( sysarg, levelLimit, circleLimit ) then
		strColor1 = Lang.ScriptTips.Color_Red
	end

	local maxTimes   	= GetActorDailyMaxTimes( sysarg, enDailyOpTimes_SpaceTrial, 0 )
	local doneTimes  	= GetActorDailyDoneTimes( sysarg, enDailyOpTimes_SpaceTrial, 0 )
	local lastTimes  	= maxTimes - doneTimes
	if lastTimes < 0 then
		lastTimes = 0
	end
	local strColor2 = Lang.ScriptTips.Color_Greed
	if lastTimes <= 0 then
		strColor2 = Lang.ScriptTips.Color_Red
	end

	--[[
	local strColor3 	= Lang.ScriptTips.Color_Greed
	local needItemId 	= SpaceTrialCfg.enterConsume[1].id
	local needItemCount = SpaceTrialCfg.enterConsume[1].count
	local hasItemNum = Actor.getItemCount( sysarg, needItemId )
	if hasItemNum < needItemCount then
		strColor3 = Lang.ScriptTips.Color_Red
	end
	local needItemname	= Item.getItemName( needItemId ) or ""
	--]]

	local openDays = System.getDaysSinceOpenServer()
	local strColor4 = Lang.ScriptTips.Color_Greed
	if openDays < SpaceTrialCfg.openServerDay then
		strColor4 = Lang.ScriptTips.Color_Red
	end

	local strCond1 = string.format( Lang.ScriptTips.LevelLimitCircleFormat, strColor1, circleLimit, levelLimit )
	local strCond2 = string.format( Lang.ScriptTips.LastTimesFormat, strColor2, lastTimes )
	--local strCond3 = string.format( Lang.ScriptTips.NeedItemFormat, strColor3, needItemname, needItemCount )
	local strCond4 = ""
	if SpaceTrialCfg.openServerDay and openDays >= SpaceTrialCfg.openServerDay then
		strCond4 = string.format( Lang.ScriptTips.LastOpenDaysLimitFormat2, strColor4  )
	else
		strCond4 = string.format( Lang.ScriptTips.LastOpenDaysLimitFormat1, strColor4, SpaceTrialCfg.openServerDay-openDays )
	end

	strCond  = string.format("%s\n%s\n%s", strCond1, strCond2, strCond4 )

	-----------------
	local strDesc = ""
	local okBtn = ""			--{按钮;样式;按钮名;函数名;描述}
	local strBtnList = ""
	strDesc 	=  Lang.ScriptTips.SpaceTrialDesc01
	okBtn1 		= "{btn;0;"..Lang.ScriptTips.ButtonEnter..";%s;}"				--{按钮;样式;按钮名;函数名;描述}
	okBtn2 		= "{btn;0;"..Lang.ScriptTips.ButtonRank..";%s;}"
	strBtnList 	= string.format(okBtn1, "EnterSpaceTrialFromNpc")
	strBtnList  = strBtnList .. string.format(okBtn2, "GetSpaceTrialRank")

	--local localFun = string.format("OpenView,%s,%d", enLinkBuyItemWnd, cfg.itemId)
	--strBtnList = strBtnList .. string.format(cfg.buyBtn, localFun)

	-----------------
	local pack = DataPack.allocPacket(sysarg, LogicCmd.npcDialogSys.sysID, LogicCmd.npcDialogSys.sub.sNpcDlgData)
	
	DataPack.writeUint64(pack, Actor.getNpc(sysarg))
	DataPack.writeByte(pack, NpcDialogType.FYSDNpcDlg)
	DataPack.writeString(pack, strCond)
	DataPack.writeString(pack, strDesc)
	DataPack.writeString(pack, strBtnList)
	DataPack.writeChar(pack, -1)
	DataPack.writeByte(pack, 0);
	DataPack.flush(pack)

	return str
end



--请求排行榜
t.GetSpaceTrialRank = function ( sysarg )
	--SendSpaceTrialRank( sysarg )
	SendSpaceTrialRank( sysarg )
end

--进入副本
t.EnterSpaceTrialFromNpc = function ( sysarg )
	EnterSpaceTrial( sysarg )
end
